const http=require("http")
const libData=require("./src/js/file")
const url=require('url')
const dbData=require("./src/js/dbData")

http.createServer((req,res)=>{
    
    let reqUrl=req.url
    

    if(/favicon\.ico/.test(reqUrl)){
        res.end()
        return
    }
    if(reqUrl==="/"){
        reqUrl="/index.html"
    }

    
    
    if(/Mylogin/.test(reqUrl)){
        let obj=url.parse(reqUrl,true,true).query
        let data=dbData(obj)
        if(data){
            res.write("1")
        }else{
            res.write("0")
        }
        
    }else {
        let path=__dirname+"/src"+reqUrl
        res.write(libData(path))
    }
    
    res.end()

}).listen(8888,()=>{
    console.log("server start...")
})

